{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ordinal Equilibria: Condorcet Consistency of Approval Voting (4.1, C.1)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:45:58.150932Z", "start_time": "2021-02-09T13:45:51.721736Z" } }, "outputs": [], "source": [ "import random\n", "import pandas as pd\n", "from poisson_approval import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:45:58.156916Z", "start_time": "2021-02-09T13:45:58.152926Z" } }, "outputs": [], "source": [ "N_SAMPLES = 10000" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:45:58.193508Z", "start_time": "2021-02-09T13:45:58.160906Z" } }, "outputs": [], "source": [ "def has_an_ordinal_equilibrium(profile):\n", " return len(profile.analyzed_strategies_ordinal.equilibria) > 0" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:45:58.226765Z", "start_time": "2021-02-09T13:45:58.197844Z" } }, "outputs": [], "source": [ "def has_an_ordinal_equilibrium_not_electing_the_cw(profile):\n", " return not profile.analyzed_strategies_ordinal.winners_at_equilibrium.issubset(profile.condorcet_winners)" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2021-01-29T11:34:18.252052Z", "start_time": "2021-01-29T11:34:18.248038Z" } }, "source": [ "## By Number of Rankings" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:46:03.460764Z", "start_time": "2021-02-09T13:45:58.230823Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
P(∃ ord eq | ∃ Cond)P(∃ ord eq not Cond | ∃ Cond)P(∃ Cond)
Number of rankings
1101
20.408301
30.24080.03780.9721
40.27420.01750.9493
50.26870.00310.9404
60.29410.00120.9367
\n", "
" ], "text/plain": [ " P(∃ ord eq | ∃ Cond) P(∃ ord eq not Cond | ∃ Cond) \\\n", "Number of rankings \n", "1 1 0 \n", "2 0.4083 0 \n", "3 0.2408 0.0378 \n", "4 0.2742 0.0175 \n", "5 0.2687 0.0031 \n", "6 0.2941 0.0012 \n", "\n", " P(∃ Cond) \n", "Number of rankings \n", "1 1 \n", "2 1 \n", "3 0.9721 \n", "4 0.9493 \n", "5 0.9404 \n", "6 0.9367 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table = pd.DataFrame(index=range(1, 7), columns=[\n", " 'P(∃ ord eq | ∃ Cond)',\n", " 'P(∃ ord eq not Cond | ∃ Cond)',\n", " 'P(∃ Cond)'\n", "])\n", "table.index.name = \"Number of rankings\"\n", "for n_rankings in table.index:\n", " def rand_profile():\n", " rankings = random.sample(RANKINGS, n_rankings)\n", " return RandProfileOrdinalUniform(orders=rankings)()\n", " p1, p2 = probability(\n", " factory=rand_profile,\n", " n_samples=N_SAMPLES,\n", " test=(has_an_ordinal_equilibrium, has_an_ordinal_equilibrium_not_electing_the_cw),\n", " conditional_on=is_condorcet\n", " )\n", " table.loc[n_rankings, 'P(∃ ord eq | ∃ Cond)'] = p1\n", " table.loc[n_rankings, 'P(∃ ord eq not Cond | ∃ Cond)'] = p2\n", " p3 = probability(\n", " factory=rand_profile,\n", " n_samples=N_SAMPLES,\n", " test=is_condorcet\n", " )\n", " table.loc[n_rankings, 'P(∃ Cond)'] = p3\n", "table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## By Subset of Rankings" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:46:12.845707Z", "start_time": "2021-02-09T13:46:03.463628Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
P(∃ ord eq not Cond | ∃ Cond)
Rankings
('abc', 'bac', 'cab')0.1299
('abc', 'acb', 'bac', 'cab')0.0590
('abc', 'acb', 'bca', 'cba')0.0094
('abc', 'acb', 'bac', 'bca', 'cab')0.0046
('abc', 'acb', 'bac', 'cba')0.0038
('abc', 'acb', 'bac', 'bca', 'cab', 'cba')0.0012
('abc',)0.0000
('abc', 'acb')0.0000
('abc', 'bac')0.0000
('abc', 'bca')0.0000
('abc', 'cba')0.0000
('abc', 'acb', 'bac')0.0000
('abc', 'acb', 'bca')0.0000
('abc', 'bca', 'cab')0.0000
('abc', 'acb', 'bac', 'bca')0.0000
\n", "
" ], "text/plain": [ " P(∃ ord eq not Cond | ∃ Cond)\n", "Rankings \n", "('abc', 'bac', 'cab') 0.1299\n", "('abc', 'acb', 'bac', 'cab') 0.0590\n", "('abc', 'acb', 'bca', 'cba') 0.0094\n", "('abc', 'acb', 'bac', 'bca', 'cab') 0.0046\n", "('abc', 'acb', 'bac', 'cba') 0.0038\n", "('abc', 'acb', 'bac', 'bca', 'cab', 'cba') 0.0012\n", "('abc',) 0.0000\n", "('abc', 'acb') 0.0000\n", "('abc', 'bac') 0.0000\n", "('abc', 'bca') 0.0000\n", "('abc', 'cba') 0.0000\n", "('abc', 'acb', 'bac') 0.0000\n", "('abc', 'acb', 'bca') 0.0000\n", "('abc', 'bca', 'cab') 0.0000\n", "('abc', 'acb', 'bac', 'bca') 0.0000" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table = pd.DataFrame()\n", "table.index.name = 'Rankings'\n", "for rankings in SETS_OF_RANKINGS_UP_TO_RELABELLING:\n", " rand_profile = RandProfileOrdinalUniform(orders=rankings)\n", " p = probability(\n", " factory=rand_profile, \n", " n_samples=N_SAMPLES,\n", " test=has_an_ordinal_equilibrium_not_electing_the_cw,\n", " conditional_on=is_condorcet\n", " )\n", " table.loc[str(rankings), 'P(∃ ord eq not Cond | ∃ Cond)'] = p\n", "table.sort_values(by='P(∃ ord eq not Cond | ∃ Cond)', ascending=False, inplace=True)\n", "table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Focus on Single-Peaked Profiles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Over the whole single-peaked domain:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:46:12.861662Z", "start_time": "2021-02-09T13:46:12.850693Z" } }, "outputs": [ { "data": { "text/plain": [ "0.059" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table.loc[\"('abc', 'acb', 'bac', 'cab')\", 'P(∃ ord eq not Cond | ∃ Cond)']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When only 3 rankings are present:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:46:12.897104Z", "start_time": "2021-02-09T13:46:12.869834Z" } }, "outputs": [ { "data": { "text/plain": [ "0.1299" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table.loc[\"('abc', 'bac', 'cab')\", 'P(∃ ord eq not Cond | ∃ Cond)']" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2021-02-09T13:46:12.910069Z", "start_time": "2021-02-09T13:46:12.902091Z" } }, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table.loc[\"('abc', 'acb', 'bac')\", 'P(∃ ord eq not Cond | ∃ Cond)']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "N.B.: the above cases actually cover all single-peaked cases, up to relabeling the candidates." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }